package com.hjq.common.validator.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @auther HJQ
 */
public class ListValConstraintVadidator implements ConstraintValidator<ListVal,Integer> {
    //初始化
    private Set<Integer> valSet=new HashSet<>();
    @Override
    public void initialize(ListVal constraintAnnotation) {
        int[] vals = constraintAnnotation.vals();
        for (int val:vals) {
            valSet.add(val);

        }

    }
//判断是否校验成功value:需要校验的值
    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return valSet.contains(integer);
    }
}
